package regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Domain {

    public static void main(final String[] args) {

        String pattern = "([a-zA-Z0-9]+[-_]?)+[a-zA-Z0-9]+(\\.[a-zA-Z]{2,4})(\\.[a-zA-Z]{2})?";
        Pattern compile = Pattern.compile(pattern);

        // For suffix
        String string = "aaaaaaa";
        Matcher matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "11231231";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "aa.b";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "aa.bb";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "aa.bbb";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "aa.bbbb";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "aa.bbbbb";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "aa.bbb.c";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "aa.bbb.cc";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "aa.bbb.ccc";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        // For prefix
        string = "a.bb";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "a-.bb";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "-a.bb";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "a-_b.bb";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));

        string = "a-b_c.bb";
        matcher = compile.matcher(string);
        System.out.println(String.format("%s : %s", string, matcher.matches()));
    }
}
